package cn.itcast.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liudo
 * @version 1.0
 * @project mq-demo
 * @description 定向交换机配置
 * @date 2023/8/19 14:03:39
 */
@Configuration
public class DirectConfiguration {

    @Bean
    public Queue directQueue1() {
        return new Queue("direct.queue1");
    }

    @Bean
    public Queue directQueue2() {
        return new Queue("direct.queue2");
    }

    @Bean
    public DirectExchange directExchange() {
        return ExchangeBuilder
                .directExchange("direct.exchange")
                .build();
    }

    @Bean
    public Binding directExchangeBinding1() {
        return BindingBuilder.bind(directQueue1())
                .to(directExchange())
                .with("direct.red");
    }

    @Bean
    public Binding directExchangeBinding2() {
        return BindingBuilder.bind(directQueue2())
                .to(directExchange())
                .with("direct.blue");
    }

    @Bean
    public Binding directExchangeBinding3() {
        return BindingBuilder.bind(directQueue1())
                .to(directExchange())
                .with("direct.green");
    }

    @Bean
    public Binding directExchangeBinding4() {
        return BindingBuilder.bind(directQueue2())
                .to(directExchange())
                .with("direct.red");
    }
}
